//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "LfmCovarianceParameterization.h"
using namespace Cephei::QL::Legacy::Libormarketmodels;
#include <gen/QL/Math/Array.h>
using namespace Cephei::QL::Math;
#undef HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Legacy::Libormarketmodels::CLfmCovarianceParameterization::CLfmCovarianceParameterization (boost::shared_ptr<QuantLib::LfmCovarianceParameterization>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phLfmCovarianceParameterization = NULL;
#endif
	_ppLfmCovarianceParameterization = &childNative;
    
}
Cephei::QL::Legacy::Libormarketmodels::CLfmCovarianceParameterization::CLfmCovarianceParameterization (QuantLib::LfmCovarianceParameterization& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phLfmCovarianceParameterization = NULL;
#endif
	_ppLfmCovarianceParameterization = new boost::shared_ptr<QuantLib::LfmCovarianceParameterization> (&childNative);
    
    _LfmCovarianceParameterizationOwner = owner;
    
}

Cephei::QL::Legacy::Libormarketmodels::CLfmCovarianceParameterization::CLfmCovarianceParameterization (CLfmCovarianceParameterization^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phLfmCovarianceParameterization = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppLfmCovarianceParameterization = new boost::shared_ptr<QuantLib::LfmCovarianceParameterization> (copy->GetShared());
        
    }
}
Cephei::QL::Legacy::Libormarketmodels::CLfmCovarianceParameterization::CLfmCovarianceParameterization (PLATFORM::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phLfmCovarianceParameterization = NULL;
#endif
	if (!t->IsSubclassOf(CLfmCovarianceParameterization::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Legacy::Libormarketmodels::CLfmCovarianceParameterization::CLfmCovarianceParameterization (QuantLib::Handle<QuantLib::LfmCovarianceParameterization>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phLfmCovarianceParameterization = &childNative;
	_ppLfmCovarianceParameterization = &static_cast<boost::shared_ptr<QuantLib::LfmCovarianceParameterization>>(childNative.currentLink());
    
    _LfmCovarianceParameterizationOwner = owner;
}
Cephei::QL::Legacy::Libormarketmodels::CLfmCovarianceParameterization::CLfmCovarianceParameterization (QuantLib::Handle<QuantLib::LfmCovarianceParameterization> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phLfmCovarianceParameterization = &childNative;
	_ppLfmCovarianceParameterization = &static_cast<boost::shared_ptr<QuantLib::LfmCovarianceParameterization>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Legacy::Libormarketmodels::CLfmCovarianceParameterization::CLfmCovarianceParameterization (QuantLib::LfmCovarianceParameterization childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phLfmCovarianceParameterization = NULL;
#endif
	_ppLfmCovarianceParameterization = new boost::shared_ptr<QuantLib::LfmCovarianceParameterization> (new QuantLib::LfmCovarianceParameterization (childNative));
    
}
#endif

Cephei::QL::Legacy::Libormarketmodels::CLfmCovarianceParameterization::~CLfmCovarianceParameterization ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppLfmCovarianceParameterization != NULL)
    {
	    delete _ppLfmCovarianceParameterization;
        _ppLfmCovarianceParameterization = NULL;
    }
}
Cephei::QL::Legacy::Libormarketmodels::CLfmCovarianceParameterization::!CLfmCovarianceParameterization ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppLfmCovarianceParameterization != NULL)
    {
	    delete _ppLfmCovarianceParameterization;
    }
}
QuantLib::LfmCovarianceParameterization& Cephei::QL::Legacy::Libormarketmodels::CLfmCovarianceParameterization::GetReference ()
{
    if (_ppLfmCovarianceParameterization == NULL) throw REFNEW NativeNullException ();
	return **_ppLfmCovarianceParameterization;
}
boost::shared_ptr<QuantLib::LfmCovarianceParameterization>& Cephei::QL::Legacy::Libormarketmodels::CLfmCovarianceParameterization::GetShared ()
{
    if (_ppLfmCovarianceParameterization == NULL) throw REFNEW NativeNullException ();
	return *_ppLfmCovarianceParameterization;
}
QuantLib::LfmCovarianceParameterization* Cephei::QL::Legacy::Libormarketmodels::CLfmCovarianceParameterization::GetPointer ()
{
    if (_ppLfmCovarianceParameterization == NULL) throw REFNEW NativeNullException ();
	return &**_ppLfmCovarianceParameterization;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::LfmCovarianceParameterization>& Cephei::QL::Legacy::Libormarketmodels::CLfmCovarianceParameterization::GetHandle ()
{
	if (_phLfmCovarianceParameterization == NULL)
	{
		_phLfmCovarianceParameterization = new Handle<QuantLib::LfmCovarianceParameterization> (*_ppLfmCovarianceParameterization);
	}
	return *_phLfmCovarianceParameterization;
}
#endif
bool Cephei::QL::Legacy::Libormarketmodels::CLfmCovarianceParameterization::HasNative () 
{
	return (_ppLfmCovarianceParameterization != NULL);
}

UInt64 Cephei::QL::Legacy::Libormarketmodels::CLfmCovarianceParameterization::Factors::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppLfmCovarianceParameterization)->factors ( );   
        UInt64 _nrv = _rv; //c1
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt64 Cephei::QL::Legacy::Libormarketmodels::CLfmCovarianceParameterization::Size::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppLfmCovarianceParameterization)->size ( );   
        UInt64 _nrv = _rv; //c1
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

